//
//  FHNetworkTool.swift
//  FHweibo
//
//  Created by 张嵩雷 on 16/4/9.
//  Copyright © 2016年 feng. All rights reserved.
//

import UIKit

import AFNetworking


// Swift中得枚举不仅可以有成员,还可以有属性,还有可以有方法
enum FHNetworkErrorEnum: Int {
    case AccessTokenEmpth = -1
    case UidEmpth = -2
    
    var errorDescription: String {
        get {
            switch self {
            case AccessTokenEmpth: return "access_token没有值"
            case UidEmpth: return "uid没有值"
            }
        }
    }
    
    //返回一个错误
    func error() -> NSError {
        
        return NSError(domain: "cn.ithema.net", code: self.rawValue, userInfo: ["errorDescription" : self.errorDescription])
    }
    
    
}



class FHNetworkTool: AFHTTPSessionManager {
    //单例
   static let sharedInstance: FHNetworkTool = {
        let tool = FHNetworkTool()
    
    //set:元素是无序的,元素不会重复
        tool.responseSerializer.acceptableContentTypes?.insert("text/plain")
        
        return tool
    }()
}


